new Vue({
  el: '#app',
  data: {
    ossImgUrl: ossImgUrl,//oss图片域名
    screenHeight: document.documentElement.clientHeight,     // 当前高度
    originHeight: document.documentElement.clientHeight,     //默认高度，用作比较
    isOriginHeight: true,    //当前高度是否仍等于默认高度
    is_server: "",//是否是老服务商 1 是 0 否
    sign_type: "",//签约类型 1 个人 2 企业
    bank_name: '',//开户行
    bank_num: '',//开户账号
    referee_phone: '',//上级手机号
    referee_name: '',//上级名称
    isReadonly: false,//推荐人姓名是否可编辑
    flag: false,//下一步是否可点击
    title: "",//标题
    audit_remark_status: '',//失败原因 默认0 1 推荐人 2 银行卡 3 其他
    audit_remark_msg: '',//失败原因msg
    audit_status: '',//审核状态 0 未提交 1 审核中 2 审核不通过 3 审核通过
    uuid: ''//主键ID 修改推荐人和银行卡使用
  },
  watch: {
    screenHeight(val) {
      if (this.originHeight - val > 60) {    //这里以防万一改了下判断形式，当屏幕高度减少了60px以上时才隐藏footer
        this.isOriginHeight = false;
      } else {
        this.isOriginHeight = true;
      }
    }
  },
  mounted() {
    // 解决底部被键盘顶起的问题
    window.onresize = () => {
      return (() => {
        this.screenHeight = document.documentElement.clientHeight;
      })()
    }
    // 缓存 小程序传来的 phone 参数（请求头用）
    if (getUrlParam("phone")) {
      local.set("phone", getUrlParam("phone"));
    }
    this.queryStatus();
  },
  methods: {
    // 查询状态，判断何去何从
    queryStatus: function () {
      var phone = local.get("phone") ? local.get("phone") : '';
      var that = this;
      get("api/enp/user/" + phone + "/pay").then(function (res) {
        if (res.data) {
          that.is_server = res.data.is_server;
          that.sign_type = res.data.sign_type;
          that.audit_remark_status = res.data.audit_remark_status;
          that.uuid = res.data.uuid;
          switch (res.data.audit_remark_status) {
            case 1://1 推荐人
              that.audit_remark_msg = '推荐人信息有误';
              that.title = "签约信息";
              break;
            case 2://2 银行卡
              that.audit_remark_msg = '银行卡信息有误';
              that.title = "银行卡信息";
              break;
            case 3://3 其他
              that.audit_remark_msg = '其他';
              that.title = "";
              that.flag = true;
              break;
          }
        }
      })
    },
    // 根据邀请码/手机号 获取推荐人姓名
    getRefereeName: function (codetel) {
      var that = this;
      var referee_phone = codetel.replace(/\s*/g, "");
      if (!referee_phone) { return }
      get("api/user/" + referee_phone).then(function (res) {
        if (res.data && res.data.realname) {
          that.referee_name = res.data.realname;
          that.isReadonly = true;
          that.mustClick();
        } else {
          that.referee_name = ""
          that.isReadonly = false;
        }
      })
    },
    // 验证银行卡号 位数验证（16位到20位），由于里面有空格，所以最小为19最大位24
    verifyBank_num: function () {
      if (!this.bank_num) { return }
      if (this.bank_num.replace(/\s*/g, "").length < 16) {
        mui.toast('开户账号必须在16位到20位之间');
        this.bank_num = "";
      }
      this.mustClick();
    },
    // 失去焦点验证下一步是否可点击
    mustClick: function () {
      if (this.audit_remark_status == 1) {
        if (!this.referee_phone || !this.referee_name) {
          this.flag = false;
        } else {
          this.flag = true;
        }
      } else if (this.audit_remark_status == 2) {
        if (!this.bank_num || !this.bank_name) {
          this.flag = false;
        } else {
          this.flag = true;
        }
      }
    },
    // 重新提交->进签约信息页
    submitAgain: function () {
      if (!this.flag) {
        return
      }
      var that = this;
      put("api/user/sign", {
        'uuid': this.uuid,
        'audit_remark_status': this.audit_remark_status,
        'referee_phone': this.referee_phone.replace(/\s*/g, ""),
        'referee_name': this.referee_name.replace(/\s*/g, ""),
        'bank_num': this.bank_num.replace(/\s*/g, ""),
        'bank_name': this.bank_name.replace(/\s*/g, "")
      }).then(function (res) {
        if (res.code == 200) {//->等待审核
          if (that.audit_remark_status == 1 || that.audit_remark_status == 2) {
            window.location.href = "wait_audit.html"
          } else {
            if (that.is_server == 1) {//是老服务商-> 资料补充页
              window.location.href = "data_supple.html";
            } else {
              if (that.sign_type == 1) {//个人签->个人认证授权页
                window.location.href = "realname_auth.html"
              } else if (that.sign_type == 2) {//企业签->商户签约
                window.location.href = "select_index.html"
              }
            }
          }
        }
      })
    }
  },
})